﻿using System;
using System.Collections;
using System.Reflection;
using log4net;
using log4net.Config;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.ServiceModel;
using System.ComponentModel;
using System.ServiceModel.Security;
using System.Collections.Generic;
using System.ServiceModel.Description;
using System.Configuration;

namespace HaiFang
{
    public enum LogType
    {
        LogType_Debug = 1,
        LogType_Info,
        LogType_Error,
        LogType_Fatal
    }
    public class LogHelper
    {
        public static string ServerName = "HaiFang";
        private LogHelper()
        {
        }

        /// <summary>
        /// 统一的写日志方法
        /// </summary>
        /// <param name="eLogType">日志类型</param>
        /// <param name="sServerName">日志服务名</param>
        /// <param name="sErrorDesc">错误描述</param>
        /// <param name="e">Exception</param>
        public static void Writelog(LogType eLogType, string sServerName, string sErrorDesc, Exception e)
        {
            ILog log = LogManager.GetLogger(sServerName);
            switch (eLogType)
            {
                case LogType.LogType_Debug:
                    {
                        log.Debug(sErrorDesc, e);
                    }
                    break;
                case LogType.LogType_Info:
                    {
                        log.Info(sErrorDesc, e);
                    }
                    break;
                case LogType.LogType_Error:
                    {
                        log.Error(sErrorDesc, e);
                    }
                    break;
                case LogType.LogType_Fatal:
                    {
                        log.Fatal(sErrorDesc, e);
                    }
                    break;
            }
        }

        public static void Writelog(LogType eLogType, string sErrorDesc, Exception e)
        {
            Writelog(eLogType, ServerName, sErrorDesc, e);
        }
    }
}
